import delimited "originspolicyideas_data.csv"

*Sponosors only for cases where the original section is in the 
replace icpsr=. if initial==0

*case_id numbers
*vawa=1
*choice=2
*dodd-frank=3
*cures=4
*first step=5
*essa=6
*farm bill=7

*Table 4
tab first_intro_type

*Table 5
sort case
bysort case: tab first_intro_type
*Reauthorizations
tab first_intro_type if case_id==1 | case_id==7 | case_id==6
*Scandals
tab first_intro_type if case_id==3 | case_id==2

*Table 7 (sums done outside STATA for bills that originate in House or Senate versions or show up first in enrolled bill)
tab bill2 if first_intro_type==4
tab bill2 if enrolled==1 & first_intro_type==4
tab bill2 if enrolled==. & first_intro_type==4

*Dodd-Frank discussion after Table 7
tab bill2 if enrolled==1 & first_intro_type==4 & case_id==3

*How Old are old ideas section 
sum day if first_intro_type==1, detail 
*Proposed before late game
sum day if first_intro_type<4 
*All sections
sum day, detail
*More than 3 years
sum day if day>1095

*Figure 1
gen years = day/365
histogram year, discrete width(1) start(0) percent xtitle("Years on Congress's Agenda") ytitle("Percentage")

*Table 8
egen tag = tag(icpsr case_id) 
egen spon_count = total(tag) if initial==1, by(case_id)
bysort case: tab spon_count if initial==1

*Table 9 
bysort case: tab democrat if first_intro_type==1 | first_intro_type==2

*Figure 2
sum ideodist_floor if initial==1 & chair==0, detail
hist ideodist_floor if initial==1 & chair==0, width(0.05) percent xtitle("Ideological Distance from Floor Median") ytitle("Percentage")

*Table 10
tab house_orig if enrolled==.
bysort case_id: tab house_orig if enrolled==.

*LES member-level analysis after Table 9
collapse (first) congress (first) sponsor (count) dwnom1 (first) chair (first) les_score (first) les_score_final if initial==1, by(congress_enr icpsr)
rename dwnom1 num_sections
drop if num_sections==0

merge 1:m congress_enr icpsr using "C:\replication\LES_Full.dta"
*Add in LES score for MCs whose ideas are not included in final measures.
replace les_score = les_score_final if les_score==. & _merge==2

*T-tests after Table 9
keep if congress_enr>110
ttest les_score_final if _merge>1, by(_merge) unpaired unequal
ttest les_score if _merge>1, by(_merge) unpaired unequal
